
$('#open').live('click',function(){
    if (typeof(popupTicketOpen)=='undefined') popupTicketOpen = new popUp();
        popupTicketOpen.load('/support/support/open' ,
        {
            title:'Edit text',                       
            buttons: [
                {
                    value: 'Submit',
                    clickFunction: function(){
                         $('#open_ticket').ajaxSubmit({
                            url: '/support/support/add',
                            type:'post',
                            success: function(response){
                                console.log(response);
                                try{
                                	errors = $.parseJSON(response);
                                	//console.log(errors.error.subject);
                                	$('#subject_err').text(errors.error.subject[0]);
                                	$('#description_err').text(errors.error.description[0]);
                                }
                                catch(e){
                                	$('#main_content').html(response);
                                	if (typeof(popupTicketOpen)!='undefined') popupTicketOpen.hide();
                                }
                                
                            }
                        });                         
                    }                    
                },
                {
                    value: 'Cancel',
                    clickFunction: function(){
                        if (typeof(popupTicketOpen)!='undefined') popupTicketOpen.hide();
                    }                    
                }
            ]
        });
});

$('#previous').live('click', function(){
	$('#main_content').load('/support/support/viewall',{'status':'open'});
});

$('#opened').live('click', function(){
	$.post('/support/support/viewall',{'status':'open'}, function(response){
		$('#main_content').html(response);
	});
});
$('#closed').live('click', function(){
	$.post('/support/support/viewall',{'status':'closed'}, function(response){
		$('#main_content').html(response);
	});
});
$('#reopened').live('click', function(){
	$.post('/support/support/viewall',{'status':'reopened'}, function(response){
		$('#main_content').html(response);
	});
});
$('#back').live('click', function(){
	$('#main_content').load('/support/support');
});
$('#more').live('click', function(){
	var request_id = $(this).parent('div').attr('rel');
	$('#main_content').load('/support/support/request',{'request_id':request_id});
});
$('#comment_form').live('click', function(){
	$(this).ajaxForm({
		success: function(response){
				$('.comments').append(response);
						return false;
				}
	});
});